home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / keyb / keymap00.zip / KEYMAP.ASM < prev    next >
Assembly Source File  |  1991-10-16  |  6KB  |  304 lines

  1. ;; keymap.asm v0.0
  2. ;; Custom Keymap Driver
  3. ;; Copyright (C) 1991  Kenneth Gober
  4. ;;
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation; either version 2 of the License, or
  8. ;; (at your option) any later version.
  9. ;;
  10. ;; This program is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;; GNU General Public License for more details.
  14. ;;
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program; if not, write to the Free Software
  17. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ;;
  19. ;; To contact the author about changes, enhancements, bug reports, or
  20. ;; other comments, send electronic mail to:
  21. ;;
  22. ;;    snow@drycas (from Bitnet sites)
  23. ;;    snow@drycas.club.cc.cmu.edu (from Internet sites)
  24. ;;
  25. ;; If you are unable to contact the author through electronic mail,
  26. ;; try sending a letter (as a last resort, only) to the following address:
  27. ;;
  28. ;;    Kenneth Gober
  29. ;;    412 Robin Road
  30. ;;    Cedar Hill, TX 75104 (USA)
  31. ;;
  32. ;; Please note that mail sent to this address may not yield a response
  33. ;; for several months!
  34. ;;
  35. ;; Version History:
  36. ;;
  37. ;;    0.0    Initial release
  38. ;;
  39.  
  40.     ideal                ; Use TASM Ideal mode syntax
  41.     p286n                ; Assemble for the 80286 (real mode)
  42.     locals    $$            ; local labels preceded by '$$'
  43.  
  44. NMAPS    =    (kmend-maptab)/96    ; number of keyboard layouts installed
  45.  
  46. kEsc    =    1            ; list of keyboard scan codes 
  47. k1    =    2
  48. k2    =    3
  49. k3    =    4
  50. k4    =    5
  51. k5    =    6
  52. k6    =    7
  53. k7    =    8
  54. k8    =    9
  55. k9    =    10
  56. k0    =    11
  57. kMinus    =    12
  58. kEqual    =    13
  59. kBS    =    14
  60. kTab    =    15
  61. kQ    =    16
  62. kW    =    17
  63. kE    =    18
  64. kR    =    19
  65. kT    =    20
  66. kY    =    21
  67. kU    =    22
  68. kI    =    23
  69. kO    =    24
  70. kP    =    25
  71. kOpen    =    26
  72. kClose    =    27
  73. kEnter    =    28
  74. kCtrl    =    29
  75. kA    =    30
  76. kS    =    31
  77. kD    =    32
  78. kF    =    33
  79. kG    =    34
  80. kH    =    35
  81. kJ    =    36
  82. kK    =    37
  83. kL    =    38
  84. kColon    =    39
  85. kQuote    =    40
  86. kTilde    =    41
  87. kLShift    =    42
  88. kPipe    =    43
  89. kZ    =    44
  90. kX    =    45
  91. kC    =    46
  92. kV    =    47
  93. kB    =    48
  94. kN    =    49
  95. kM    =    50
  96. kComma    =    51
  97. kDot    =    52
  98. kSlash    =    53
  99. kRShift    =    54
  100. kStar    =    55
  101. kAlt    =    56
  102. kSpace    =    57
  103. kCaps    =    58
  104. kF1    =    59
  105. kF2    =    60
  106. kF3    =    61
  107. kF4    =    62
  108. kF5    =    63
  109. kF6    =    64
  110. kF7    =    65
  111. kF8    =    66
  112. kF9    =    67
  113. kF10    =    68
  114. kNum    =    69
  115. kScroll    =    70
  116. kp7    =    71
  117. kp8    =    72
  118. kp9    =    73
  119. kpMinus    =    74
  120. kp4    =    75
  121. kp5    =    76
  122. kp6    =    77
  123. kpPlus    =    78
  124. kp1    =    79
  125. kp2    =    80
  126. kp3    =    81
  127. kp0    =    82
  128. kpDot    =    83
  129. kpSysRq    =    84
  130. kF11    =    87
  131. kF12    =    88
  132.  
  133. rhds    equ    (rh ds:si)
  134. rhes    equ    (rh es:di)
  135.  
  136. macro    pushfm
  137.     pushf
  138.     push    cs
  139. endm
  140.  
  141. macro    popfm
  142.     call    iretm
  143. endm
  144.  
  145. struc    rh                ; request header
  146. len    db    ?
  147. dev    db    ?
  148. cmd    db    ?
  149. st    dw    ?
  150. rsvd    dq    ?
  151. ct    db    ?
  152. aoff    dw    ?
  153. aseg    dw    ?
  154. dptr    dd    ?
  155. ends
  156.  
  157. segment    code    use16
  158.  
  159. devhdr    dd    -1            ; device header
  160. devflg    dw    0a000h
  161. devstr    dw    kmstr
  162. devint    dw    kmint0
  163. devnam    db    '-KEYMAP-'
  164.  
  165. mapoff    dw    maptab            ; pointer to active keymap
  166.  
  167.     align    4            ; align rhptr on a dword boundary
  168.  
  169. label    rhptr    dword            ; pointer to request header
  170. rhoff    dw    ?
  171. rhseg    dw    ?
  172.  
  173. proc    kmstr    far            ; strategy routine
  174.     assume    cs:code
  175.  
  176.     mov    [rhoff], bx
  177.     mov    [rhseg], es
  178.     ret
  179. endp
  180.  
  181. proc    kmint    far            ; resident interrupt routine
  182.     assume    cs:code
  183.  
  184.     push    si            ; save registers
  185.     push    ds
  186.     lds    si, [rhptr]        ; ds:si = request header
  187.     mov    [rhds.st], 8103h    ; return error (unknown command)
  188.     pop    ds            ; restore registers
  189.     pop    si
  190.     ret
  191. endp
  192.  
  193. label    hdrend    unknown            ; HEADER SECTION ENDS HERE
  194.  
  195.     align    4            ; align ptrs on a dword boundary
  196.  
  197. label    intptr    dword            ; pointer to interrupt handler
  198. intoff    dw    15h*4
  199. intseg    dw    0
  200.  
  201. proc    kmmap    far            ; interrupt handler
  202.     assume    cs:code
  203.  
  204.     pushfm                ; push flags
  205.     cmp    ah, 4fh            ; is it keyboard intercept?
  206.     je    short $$1
  207.     popfm                ; pop flags
  208.     jmp    [intptr]        ; chain to old handler
  209.  
  210. $$1:    push    ds            ; save registers
  211.     push    bx
  212.     push    ax            ; save original scancode
  213.     and    al, 7fh            ; mask break bit
  214.     cmp    al, 96            ; in range?
  215.     jae    short keyok
  216.     cmp    al, kF1            ; keymap select key?
  217.     jb    short xlate
  218.     cmp    al, kF1+NMAPS
  219.     jae    short xlate
  220.     xor    bx, bx            ; valid function key
  221.     mov    ds, bx            ; check shift keys
  222.     mov    bl, [ds:417h]
  223.     and    bl, 0eh            ; alt-ctrl-leftshift
  224.     cmp    bl, 0eh
  225.     jne    short xlate
  226.     sub    ax, 4f00h+kF1        ; change maps
  227.     imul    bx, ax, 96        ; 98 keys per map
  228.     lea    bx, [ds:maptab+bx]    ; maps start at maptab
  229.     mov    [cs:mapoff], bx
  230.     pop    ax            ; restore original scancode
  231.     pop    bx            ; restore registers
  232.     pop    ds
  233.     popfm                ; pop flags
  234.     clc                ; but clear carry to ignore this key
  235.     ret    2            ; don't restore flags on IRET
  236.  
  237. xlate:    mov    bx, [cs:mapoff]        ; ds:bx = keymap
  238.     pop    ax            ; restore original scancode
  239.     mov    ah, al
  240.     and    ah, 80h            ; save make/break bit in ah
  241.     and    al, 7fh            ; look up scancode
  242.     xlat    [cs:0]
  243.     or    al, ah            ; restore make/break bit
  244.     mov    ah, 4fh            ; restore unused registers
  245.  
  246. done:    pop    bx            ; restore registers
  247.     pop    ds
  248.     popfm                ; pop flags
  249. iretm:    iret
  250.  
  251. keyok:    pop    ax            ; no translation necessary
  252.     jmp    short done        ; restore scancode and return
  253. endp
  254.  
  255. label    maptab    unknown            ; keymap tables
  256.     include    "sholes.kbd"        ; default keymap
  257.     include "dvorak.kbd"        ; alternate keymap (up to 9)
  258.  
  259. label    kmend    unknown            ; RESIDENT PORTION ENDS HERE
  260.  
  261. proc    kmint0    far            ; initial interrupt routine
  262.     assume    cs:code, ds:code
  263.  
  264.     pushfm                ; save flags
  265.     pusha                ; save registers
  266.     push    ds
  267.     push    es
  268.     push    cs
  269.     pop    ds
  270.     les    di, [rhptr]        ; es:di = request header
  271.     mov    [rhes.st], 8103h    ; assume error (unknown command)
  272.     mov    al, [rhes.cmd]        ; only cmd 0, INIT is legal
  273.     or    al, al
  274.     jnz    short exit
  275.     mov    ah, 9            ; write banner
  276.     mov    dx, offset eHello
  277.     int    21h
  278.     mov    [devint], offset kmint    ; install resident interrupt routine
  279.     mov    [rhes.aseg], cs        ; discard initialization section
  280.     mov    [rhes.aoff], offset kmend
  281.     mov    [rhes.st], 0100h    ; return success code
  282.     les    di, [intptr]        ; hook into INT 15 vector
  283.     mov    ax, [es:di]        ; save old offset
  284.     mov    [intoff], ax
  285.     mov    ax, [es:di+2]        ; save old segment
  286.     mov    [intseg], ax
  287.     cli                ; disable interrupts and hook in
  288.     mov    [word es:di], offset kmmap
  289.     mov    [es:di+2], cs
  290.  
  291. exit:    pop    es            ; restore registers
  292.     pop    ds
  293.     popa
  294.     popfm                ; pop flags
  295.     ret
  296. endp
  297.  
  298. eHello    db    'Custom Keymap Driver v0.0', 13, 10
  299.     db    'Copyright (C) 1991  Kenneth Gober'
  300. eNL    db    13, 10, 13, 10, '$'
  301.  
  302. ends    code
  303.     end
  304.